<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

//权限验证
if( Role::init() == false ){
	exit('没有权限');
}

$db = new DB();

$orders = isset($_POST['orders']) ? $_POST['orders'] : 0;
$id = isset($_POST['id']) ? $_POST['id'] : 0;

//检验必要参数
if( !is_array($orders) || !is_array($id) || count($orders)!=count($id) ){
	echo '<script>alert("参数有误！");window.history.go(-1);</script>';
	exit;
}

$orders_id_array = array();
foreach($id as $k=>$v){
	$orders_id_array[$v] = $orders[$k];
}

foreach($orders_id_array as $key=>$val){
	$data = array('orders'=>$val);
	$db->table('analytic_codes')->where('id='.$key)->update($data)->run();

}

echo '<script>alert("排序成功！");window.location.href="/www/admin/analytic_code/code_lists.php";</script>';
exit;